package controllers;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import service.RegisterService;
import entity.register;

@Controller
@RequestMapping("/RegisterController")
public class RegisterController  {

	@Autowired
	private RegisterService fs; 
	private static List<register> f;
	{
		f = new ArrayList<register>();
	}
	@RequestMapping("find")
	public ModelAndView  find(register f){
		ModelAndView mv = new ModelAndView();
		register fx=  fs.find(f);
		if(fx!=null){ 
 			mv.setViewName("yiyuan");
 			mv.addObject("registers", fs.getAll());
			 
		}else{
			return new ModelAndView("index");
		}
		return mv;
	}
	     
	 
	
	@RequestMapping("showAll")
	public ModelAndView showAll() {
		ModelAndView mv=new ModelAndView();
		mv.setViewName("showall");
		mv.addObject("registers", fs.getAll());
		return mv;
	}
	@RequestMapping("add")
	public String add(register f) {
		
		if(fs.add(f)) {
			return "redirect:showAll";	
		}else {
			return "false";
		}
		
	}
	@RequestMapping("delete")
	public String delete(register r) {
		
		if(fs.delete(r.getId())) {
			return "redirect:showAll";	
		}else {
			return "index";
		}
	}
	
}
                                                                          